﻿using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Biomedica.Graphics;
using NuiDicomPlayer.Nui.Gestures;

namespace NuiDicomPlayer.Nui.NavigationEngine
{
    public abstract class Detectors
    {
        public Microsoft.Kinect.Skeleton[] BufferdSkeletons { set; get; }

         /// <summary>
        /// Find MA
        /// </summary>
        /// <returns></returns>
        public Vector3 FindMA()
        {
            Vector3 maV = Vector3.One;
            double ma = 10000000;
           
            foreach (Skeleton s in BufferdSkeletons)
             {

                        /// Calculate the MA of center of gravity using Vecdtor3
                        /// Ignore any error
                 if(s!=null)
                   maV += new Vector3(s.Position.X, s.Position.Y, s.Position.Z);


              }

            return maV;
        }
        public Vector3 FindMA(JointType J)
        {
            Vector3 maV = Vector3.One;
            double ma = 10000000;
            if(BufferdSkeletons!=null)
            foreach (Skeleton s in BufferdSkeletons)
            {

                /// Calculate the MA of center of gravity using Vecdtor3
                /// Ignore any error
                if(s!=null)
                maV += new Vector3(s.Joints[J].Position.X, s.Joints[J].Position.Y, s.Joints[J].Position.Z);


            }

            return maV;
        }
        public static bool isSkeletonsStable(Skeleton[] s, double th)
        {
            return false;
        }
     
    }

    public abstract class MotionDetector : Detectors
    {
        public Microsoft.Kinect.Joint ReferanceJoint { set; get; }
        public Vector3 Distance { get; set; }
        public double XThreshold { set; get; }
        public double YThreshold { set; get; }
        public double ZThreshold { set; get; }
        public abstract Vector3 GetHandMotionState(Skeleton[] BufferdSkeletons);
        public Vector3 DetectMotion(JointType joint_type,Skeleton[] BufferdSkeletons)
        {
             this.BufferdSkeletons = BufferdSkeletons;
              Vector3 v = FindMA(joint_type);
              Vector3 Rv = new Vector3(ReferanceJoint.Position.X, ReferanceJoint.Position.Y, ReferanceJoint.Position.Z);
              Distance = Rv.Distance(v);
            return Distance;
        }
        public void SetReferanceJoint(JointType joint_type,Skeleton[] BufferdSkeletons)
        {
            this.BufferdSkeletons = BufferdSkeletons;
                if (BufferdSkeletons[0] != null)
                    ReferanceJoint = BufferdSkeletons[0].Joints[joint_type];
               BufferdSkeletons = null;
        }
      
    }


    [Flags()]
    public enum JointDirections
    {
        STABLE,
        Q1,
        Q2
      

      
        
    }
}
